package com.ocom.accesservice.service.impl;


import com.ocom.accesservice.service.MjDeviceInfoService;
import com.ocom.accesservice.service.WhiteInfoService;
import com.ocom.accesservice.service.WhiteRecodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;



@Service
public class WhiteRecodeServiceImpl  implements WhiteRecodeService {

    @Autowired
    private  WhiteInfoService whiteInfoService;
    @Autowired
    private MjDeviceInfoService mjDeviceInfoService;

    @Override
    public boolean addPerson(Long companyId, Long areaNo, Long pId) {
        return common( companyId,  areaNo,  pId,1);
    }

    @Override
    public boolean delPerson(Long companyId, Long areaNo, Long pId) {
        return common( companyId,  areaNo,  pId,0);
    }

    public boolean common(Long companyId, Long areaNo, Long pId,Integer type){
        /**
         * a）删除门禁白名单表mj_white_info所有com_id、area_id、p_id匹配的记录；
         * 	b）门禁白名单表mj_white_info添加记录：
         * 			mj_white_info .com_id = CompanyID，
         * 			mj_ white _info .area_id = area_no，
         * 			mj_ white _info .p_id =P_ID，
         * 			mj_ white _info .state=0 (添加 删除是1)
         * 	c）修改机器标志表mj_device_info中所有com_id、area_id匹配的记录：
         * 			mj_device_info .list_state =1
         */
        //a
        whiteInfoService.delInfo(companyId,areaNo,pId);
        if(type==0){
            whiteInfoService.addInfo(companyId,areaNo,pId,1L);
        }else{
            whiteInfoService.addInfo(companyId,areaNo,pId,0L);
        }
        mjDeviceInfoService.updateMachTip(companyId,areaNo);
        return true;
    }

    @Override
    public boolean cleanPerson(Long companyId, Long areaNo) {
        return whiteInfoService.cleanInfo(companyId,areaNo);
    }

    /**
     * 全量下传门禁白名单
     * @param companyId
     * @param machId
     * @return
     */
    @Override
    public boolean downloadAll(Long companyId, Long machId) {
        return mjDeviceInfoService.downloadAll(companyId,machId);
    }
}
